"use strict";

/* global $ RemoveNewFreeOption AddNewFreeOption */

/**
 * 函数用于在小类tag点击的时候触发
 * @param {string} val 添加DIY表单的小类tag名称，exp：银行
 */
function AddNewFreeOption(val) {
  /** 获取对应小类id（数据库意义的id） */
  var uID = $("input#" + val).attr("value");
  /** 获取服务器上的表单数据 */
  var ajaxUrl = String($("#get_new_free_form").val());
  $.ajax(ajaxUrl, {
    method: "POST",
    data: { m_group: uID },
    success: function success(data) {
      // data.id 是数据库的表单id，至少目前看来是废的，已和后端确认
      // if (data.m_id) {
      if (data.formData.length > 0) {
        writeBackDIYForm(data);
      } else {
        addNewHiddenFree(11, uID, val);
      }
    },
    error: function error(data) {
      console.clear();
      console.log(data);
    }
  });
}

/** 这个函数究竟要做什么：
 * 1：获取对话框的东西
 * 2：构建get链接
 * 3：ajax返回id后构建相应的选项和隐藏checkbox，并把val上去列表中
 * debugID是返回的
 * var newTagButton = `<input type="checkbox" name="${debugID}" id="check_${debugID}" value="${val}" checked>`
 * var button = `<span class="tag_content"><a inori-data='${val}' id="${debugID}">${val}</a></span>`
 * 4：ajax完成后删除自身
 */
function ajaxAddNewTag(_this, val, urlBase) {
  /** debug数据 */
  _this.setAttribute("onsubmit", "return false");
  var debugID = 999;
  var mainName = "";
  var altName = "";
  var summary = "";
  $.each($(_this).children('input[type="text"]'), function(k, v) {
    var switchObj = {
      0: function _() {
        mainName = $(this).val();
        console.log(mainName);
      },
      1: function _() {
        altName = $(this).val();
        console.log(altName);
      },
      2: function _() {
        summary = $(this).val();
        console.log(summary);
      }
    };
    switchObj[k].call(v);
  });
  /** get 的方式放上去，返回一个ID */
  /** 补一个ajax后才给后端 */
  var selectedValue = $("#dalei")
    .children("option:selected")
    .val();
  var ajaxUrl =
    urlBase +
    "?type=0&dalei=" +
    selectedValue +
    "&mainName=" +
    mainName +
    "&altName=" +
    altName +
    "&summary=" +
    summary;

  $.get(ajaxUrl, function(responseID) {
    /** 标签隐藏选框 */
    var newTagButton =
      '<input type="checkbox" name="check[]" id="' +
      val +
      '" value="' +
      responseID +
      '" checked>';
    $("#hidden_tag").append(newTagButton);
    /** 可见选框 */
    var button =
      '<span class="tag_content active"><a inori-data=\'' +
      val +
      "' right-click='true' id=\"_" +
      val +
      '">' +
      val +
      "</a></span>";
    $("#xiaolei_tag_list_button").prepend(button);
    /** 恢复标签栏可见 */
    $(".tag_search_list").css("visibility", "visible");
    /* 还原网页标题 */
    var prevTitle = localStorage.getItem("prevTitle");
    if (prevTitle) $(document).attr("title", prevTitle);
    /** 清空对话栏 */
    $("#add_new_tag_content").empty();
    /** 自动补全列表中添加一个 */
    window.tagList.push(val);
    /** 解决焦点的问题 */
    $(".tag-editor.ui-sortable li:eq(-1)").remove();
    $("#xiaolei_tag_list").tagEditor("addTag", val, true);

    /** 在文件add_free_option.js定义 */
    // AddNewFreeOption(val)
    return false;
  });
  return false;
}
/** 清空父级元素 */
function deleteThis(_this) {
  $(_this.parentElement.parentElement.parentElement)
    .prev()
    .css("visibility", "visible");
  $(_this.parentElement).empty();
}
/** 清空父级的父级元素 */
function deleteThisPar(_this) {
  $(_this.parentElement.parentElement).empty();
}
/** 清除利息颜色的父级元素 */
function deleteThisLX(_this) {
  var urlBase = $("#del_lixi").val();
  var LXId = $(_this)
    .closest("div")
    .prev("input")
    .val();

  $.ajax({
    type: "POST",
    url: urlBase,
    data: { id: LXId },
    async: false,
    cache: false
  })
    .done(function(data) {
      if (data.code === 200) {
        console.log(data);
        // 成功删除颜色
        var lixiColorEleID = $(_this)
          .siblings("input")
          .attr("inori-data");
        $("#" + lixiColorEleID).remove();
        $(_this.parentElement.parentElement).empty();
      } else {
        alart("失败");
      }
    })
    .fail(function(data) {
      alart("失败");
    });
}
/** 清空父级的父级的父级元素 */
function delete_this_par(_this) {
  console.log(_this);
  // $(_this.parentElement.parentElement).empty()
}

// 添加征信查询要求
var zhengxinChaxunCount = 0;
function add_zhengxin_chaxun() {
  zhengxinChaxunCount++;
  var zhengxin_box_string = ('\n<div class="zhengxin_sec_box">\n  <div id = \'add_new_zhengxin_' +
    zhengxinChaxunCount +
    '\' onclick="deleteThis(this)" class = \'delete_this_par\'><img src="/Application/Admin/View/Public/images/set_chanpin_popup/u566.png" alt="u566" style="width:100%"></div>\n  <div class="zhengxin_line">\n    <span>\u67E5\u8BE2\u6B21\u6570\uFF1A </span>\n    <label style="width:30%;"><input checked type="radio" name="zhengxin_chaxun_' +
    zhengxinChaxunCount +
    '" id="zhengxin_chaxun_' +
    zhengxinChaxunCount +
    '_1" value="\u4E0D\u770B\u67E5\u8BE2\u6B21\u6570">\u4E0D\u770B\u67E5\u8BE2\u6B21\u6570</label>\n    <label><input type="radio" name="zhengxin_chaxun_' +
    zhengxinChaxunCount +
    '" id="zhengxin_chaxun_' +
    zhengxinChaxunCount +
    '_2" value="\u770B\u67E5\u8BE2\u6B21\u6570">\u770B\u67E5\u8BE2\u6B21\u6570</label>\n  </div>\n  <div class="zhengxin_line">\n    <span>\u67E5\u8BE2\u8BA1\u7B97\u6807\u51C6\uFF1A </span>\n    <label><input checked type="checkbox" name="zhengxin_jisuan_biaozhun_' +
    zhengxinChaxunCount +
    '[]" id="zhengxin_jisuan_biaozhun_' +
    zhengxinChaxunCount +
    '_1">\u8D37\u6B3E\u7533\u8BF7</label>\n    <label><input type="checkbox" name="zhengxin_jisuan_biaozhun_' +
    zhengxinChaxunCount +
    '[]" id="zhengxin_jisuan_biaozhun_' +
    zhengxinChaxunCount +
    '_2" >\u4FE1\u7528\u5361\u67E5\u8BE2</label>\n    <label><input type="checkbox" name="zhengxin_jisuan_biaozhun_' +
    zhengxinChaxunCount +
    '[]" id="zhengxin_jisuan_biaozhun_' +
    zhengxinChaxunCount +
    '_3" >\u4E2A\u4EBA\u67E5\u8BE2</label>\n    <label><input type="checkbox" name="zhengxin_jisuan_biaozhun_' +
    zhengxinChaxunCount +
    '[]" id="zhengxin_jisuan_biaozhun_' +
    zhengxinChaxunCount +
    '_4" >\u4FDD\u524D\u5BA1\u6279</label>\n  </div>\n  <div class="zhengxin_line">\n    <span>\u67E5\u8BE2\u8BA1\u7B97\u8DE8\u5EA6\uFF1A</span>\n    <!-- \u591A\u5C11\u6708\u5185 -->\n    <label>\n      <select name="zhengxin_qinei_' +
    zhengxinChaxunCount +
    '" id="zhengxin_qinei_' +
    zhengxinChaxunCount +
    '">\n        <option value="1">1\u4E2A\u6708</option>\n        <!-- \u987A\u5E8F -->\n        <option value="36">36\u4E2A\u6708</option>\n      </select>\n      \u5185\n    </label>\n  </div>\n  <div class="zhengxin_line">\n    <span>\u4E0D\u80FD\u8D85\u8FC7\uFF1A </span>\n    <label>\n        <select name="zhengxin_max_chaxun_' +
    zhengxinChaxunCount +
    '" id="zhengxin_max_chaxun_' +
    zhengxinChaxunCount +
    '">\n          <option value="1">1\u6B21</option>\n          <!-- \u987A\u5E8F -->\n          <option value="20">20\u6B21\u6216\u4EE5\u4E0A</option>\n        </select>\n      </label>\n  </div>\n</div>').trim();
  $("#zhengxin_chaxun_box").append(zhengxin_box_string);
}

$(document).ready(function() {
  // 大类修改 ajax
  var xiaoleiGet = $("#get_xiaolei_tag").val();
  $("#dalei").on("change", function() {
    var selectedValue = $(this)
      .children("option:selected")
      .val();

    // 修改隐藏color form区域
    $("#dalei_color").val(selectedValue);

    var textButton = "";
    var hiddenButton = "";
    $("#xiaolei_tag_list")
      .next(".tag-editor")
      .find(".tag-editor-delete")
      .click();
    $("#xiaolei_tag_list").tagEditor("destroy");
    $("#xiaolei_tag_list").val();
    $("#xiaolei_tag_list_button").empty();
    $("#hidden_tag").empty();
    $.get(xiaoleiGet + "?id=" + selectedValue, function(data) {
      $.each(data, function(k, v) {
        console.log(k);
        console.log(v);
        textButton +=
          '<span class="tag_content"><a inori-data=\'' +
          v.name +
          "' right-click='xiaolei' id=\"_" +
          v.name +
          '">' +
          v.name +
          "</a></span>";
        hiddenButton +=
          '<input type="checkbox" name="check[]" value = \'' +
          v.id +
          "' id=\"" +
          v.name +
          '">';
      });
      textButton += "<div id='add_new_tag_content'></div>";
      $("#xiaolei_tag_list_button").prepend(textButton);
      $("#hidden_tag").prepend(hiddenButton);
    });

    // $.get(`${xiaoleiGet}?value=${selectedValue}`, function (data) {
    //   console.log(data)
    //   // [["name"=>"kk", "value"=>"1",]["name"=>'kk',"uk"=>"2"]]

    // 搜索框逻辑
    $("#xiaolei_tag_list").tagEditor({
      initialTags: [],
      clickDelete: true,
      placeholder: "请点选或输入标签，点击空白处确认添加",
      autocomplete: {
        delay: 0,
        position: { collision: "flip" },
        source: window.tagList
      },
      beforeTagSave: function beforeTagSave(field, editor, tags, tag, val) {
        // 有就直接加，没有就添加
        // console.dir(field)
        // console.dir(editor)
        // console.dir(tags)// 添加前有的
        // console.log(tag)// 添加的
        // console.dir(val)// 添加的
        /** 验证是否存在，通过选取inori-data为val的元素的id来实现 */
        var isHas = $(
          '#xiaolei_tag_list_button.tag_row [inori-data="' + val + '"]'
        ).attr("id");

        /** ajax地址本体，不含参数 */
        var urlBase = document.getElementById("add_xiaolei_tag").value;

        if (!isHas) {
          // 不存在
          /** 可见对话框元素字符串，应附在$('#add_new_tag_content')内 */
          var addNewOption =
            '<form autocomplete="off" method="get" onsubmit=\'return ajaxAddNewTag(this, "' +
            val +
            '", "' +
            urlBase +
            "\")' id='newTagOption'><input type=\"text\" class='main_name' placeholder=\"\u6B63\u540D\" value='" +
            val +
            "'><input class='alt_name' type=\"text\" placeholder=\"\u522B\u540D\"> <input class= 'name_summary' type=\"text\" placeholder=\"\u7B80\u77ED\u5907\u6CE8\"><input type='submit' class='submit_ajax' value='\u786E\u5B9A'><span onclick='deleteThis(this)'>\u53D6\u6D88</span></form>";

          /** 附加对话框，将在确定按钮点击时消失 */
          $("#add_new_tag_content").append(addNewOption);
          $(".tag_search_list").css("visibility", "hidden");
          localStorage.setItem("prevTitle", String($(document).attr("title")));
          $(document).attr("title", "请先完成当前操作");
          $("#add_new_tag_content .alt_name").focus();
          // 不添加
          return false;
        } else {
          // 存在的
          $("#hidden_tag #" + val).prop("checked", true);
          // 检查有没有active
          if (
            !$("#xiaolei_tag_list_button #_" + val)
              .closest(".tag_content ")
              .hasClass("active")
          ) {
            $("#xiaolei_tag_list_button #_" + val)
              .closest(".tag_content ")
              .addClass("active");
          }
          /** 在文件add_free_option.js定义 */
          AddNewFreeOption(val);
        }
      },
      beforeTagDelete: function beforeTagDelete(field, editor, tags, val) {
        // console.dir(field)
        // console.dir(editor)
        // console.dir(tags)// 去除前
        // console.dir(val)// 去除的那个
        $("#hidden_tag #" + val).prop("checked", false);
        if (
          $("#xiaolei_tag_list_button #_" + val)
            .closest(".tag_content ")
            .hasClass("active")
        ) {
          $("#xiaolei_tag_list_button #_" + val)
            .closest(".tag_content ")
            .removeClass("active");
        }
        // $(`span.tag_content>a[inori-data=${val}]`).off('click', removeTagClick)
        /** 在文件add_free_option.js定义 */
        RemoveNewFreeOption(val);
      }
    });
  });

  // 点选框逻辑
  $(".multi_row_xiaolei_tag_search").on("click", function(e) {
    var target = e.target;
    var data = target.getAttribute("inori-data");
    if (
      target.nodeName.toLowerCase() === "a" &&
      data !== undefined &&
      !target.parentElement.classList.contains("active")
    ) {
      $("#xiaolei_tag_list").tagEditor("addTag", data, true);
      target.parentElement.classList.add("active");
      target.addEventListener(
        "click",
        function removeTagClick(e) {
          e.target.parentElement.classList.remove("active");
          $("#xiaolei_tag_list").tagEditor(
            "removeTag",
            e.target.getAttribute("inori-data"),
            true
          );
          e.stopPropagation();
        },
        {
          once: true
        }
      );
      console.log(data);
    } else if (
      target.nodeName.toLowerCase() === "a" &&
      data !== undefined &&
      target.parentElement.classList.contains("active")
    ) {
      target.parentElement.classList.remove("active");
      $("#xiaolei_tag_list").tagEditor("removeTag", data, true);
      e.stopPropagation();
    }
  });
  // // })

  // 添加新利息
  if (window.lixi_count === undefined) {
    window.lixi_count = 0;
  }
  $("#add_new_lixi").on("click", function() {
    $("#add_new_lixi").css("visibility", "hidden");
    localStorage.setItem("prevTitle", String($(document).attr("title")));
    $(document).attr("title", "请先完成当前操作");
    var addNewListUrl = String($("#add_lixi").val());
    // <input type="hidden" name="商品id" class='php_g_id' value='{$vo.g_id}' form='not_submit'>
    var gIDArray = location.href.match(/\/id\/(\d+)\//);
    var gID = "";
    if (gIDArray === null || gIDArray === undefined) {
      throw new Error("页面地址错误");
    } else {
      gID = gIDArray[1];
    }

    // ajax begin
    $.post("" + addNewListUrl, { g_id: gID }, function(data) {
      $("#add_new_lixi").css("visibility", "visible");
      /* 还原网页标题 */
      var prevTitle = localStorage.getItem("prevTitle");
      if (prevTitle) $(document).attr("title", prevTitle);
      if (data.code !== 1 && data.code !== 2) {
        throw new Error(
          "\u65B0\u5EFA\u5229\u606F\u9519\u8BEF\uFF1A\u8FD4\u56DE\u6570\u636Ecode = " +
            data.code +
            ",message = " +
            data.message
        );
      }
      var lixiId = window.lixi_count;
      var sample = ('\n        <div class="lixi_fenbu_main" id=\'lixi_fenbu_main_' +
        lixiId +
        '\'>\n          <input type="text" name="sanwei[lixi' +
        window.lixi_count +
        '][lixi_min]" placeholder="\u6700\u4F4E\u5229\u606F" class = \'min_lixi\'>\n          <input type="text" name="sanwei[lixi' +
        window.lixi_count +
        '][lixi_max]" placeholder="\u6700\u9AD8\u5229\u606F">\n          <input type="text" name="sanwei[lixi' +
        window.lixi_count +
        '][edu_min]" placeholder="\u6700\u4F4E\u989D\u5EA6">\n          <input type="text" name="sanwei[lixi' +
        window.lixi_count +
        '][edu_max]" placeholder="\u6700\u9AD8\u989D\u5EA6">\n          <select name="sanwei[lixi' +
        window.lixi_count +
        '][huankuan]" class=\'huankuan_fangshi\'>\n            <option value="0" selected>\u8FD8\u6B3E\u65B9\u5F0F</option>\n            <option value="\u7B49\u989D\u672C\u606F">\u7B49\u989D\u672C\u606F</option>\n            <option value="\u7B49\u989D\u672C\u91D1">\u7B49\u989D\u672C\u91D1</option>\n            <option value="\u7B49\u672C\u7B49\u606F">\u7B49\u672C\u7B49\u606F</option>\n            <option value="\u5148\u606F\u540E\u672C">\u5148\u606F\u540E\u672C</option>\n          </select>\n          <input type="num" name="sanwei[lixi' +
        window.lixi_count +
        '][fenqi_max]" placeholder="\u6700\u957F\u5206\u671F 1~360" required class=\'max_time\'>\n          <input type="text" name="sanwei[lixi' +
        window.lixi_count +
        '][fangkuan_shouxufei]" placeholder="\u653E\u6B3E\u624B\u7EED\u8D39">\n          <input type="text" name="sanwei[lixi' +
        window.lixi_count +
        '][daishou]" placeholder="\u4EE3\u6536">\n          <input type="text" name="sanwei[lixi' +
        window.lixi_count +
        '][fandian]" placeholder="\u8FD4\u70B9">\n          <input type="text" name="sanwei[lixi' +
        window.lixi_count +
        '][fangkuan_time]" placeholder="\u653E\u6B3E\u65F6\u95F4" value=\'\' required>\n          <textarea name="sanwei[lixi' +
        window.lixi_count +
        '][du_zhuxi]" id="edu_zhuhxi" placeholder="\u5229\u606F\u989D\u5EA6\u5907\u6CE8" style=\'width: 100%;\'></textarea>\n          <input type="hidden" name="sanwei[lixi' +
        window.lixi_count +
        '][id]" value="' +
        data.data +
        "\">\n          <div class='lixi_sample_value' id='" +
        lixiId +
        "'><input form='hidden_color_placeholder' inori-data='color_lixi" +
        lixiId +
        "' id=\"color" +
        lixiId +
        '" type="text" name="color1" value="#000" />\u6BCF10\u4E07\u6708\u4F9B:\uFFE5<span class="lixi_recal"></span>(36\u671F)<span class=\'shouldMind\' style=\'display:none;\'>36\u671F\u540E\u8FD8\u672C</span><span id = \'remove_this_lixi\' onclick=\'deleteThisLX(this)\'><img src="/Application/Admin/View/Public/images/set_chanpin_popup/u566.png" alt="u566" style="width:100%"></span></div>\n        </div>\n        <script>\n          $(\'#lixi_fenbu_main_' +
        lixiId +
        "').find('.huankuan_fangshi').on({change: recalLX}, {})\n          $('#lixi_fenbu_main_" +
        lixiId +
        "').find('.min_lixi').on({change: recalLX}, {})\n          $('#lixi_fenbu_main_" +
        lixiId +
        "').find('.max_time').on({change: recalLX}, {})\n        </script>").trim();
      var colorForm = ('\n      <form autocomplete="off" id="color_lixi' +
        lixiId +
        '">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][min_lx]" id="sanwei[lixi' +
        lixiId +
        '][lixi_min]">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][max_lx]" id="sanwei[lixi' +
        lixiId +
        '][lixi_max]">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][min_ed]" id="sanwei[lixi' +
        lixiId +
        '][edu_min]">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][max_ed]" id="sanwei[lixi' +
        lixiId +
        '][edu_max]">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][repayments]" id="sanwei[lixi' +
        lixiId +
        '][huankuan]">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][installment_fq]" id="sanwei[lixi' +
        lixiId +
        '][fenqi_max]">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][handling]" id="sanwei[lixi' +
        lixiId +
        '][fangkuan_shouxufei]">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][collection]" id="sanwei[lixi' +
        lixiId +
        '][daishou]">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][return]" id="sanwei[lixi' +
        lixiId +
        '][fandian]">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][fangkuan_time]" id="sanwei[lixi' +
        lixiId +
        '][fangkuan_time]">\n        <input value=\'#00000\' type="text" name="sanwei[lixi][lx_remark]" id="sanwei[lixi' +
        lixiId +
        '][du_zhuxi]">\n      </form>\n      ').trim();
      $(".lixi_fenbu").append(sample);
      $("#color_form_inside").append(colorForm);
      // 计数器自增，必须是填完才增
      window.lixi_count++;
      $("#color" + lixiId).colorPicker({
        onColorChange: function onColorChange(id, newValue) {
          var targetID = $(this)
            .prev("input")
            .attr("inori-data");
          var targetEle = $("#" + targetID + " input");
          var _iteratorNormalCompletion = true;
          var _didIteratorError = false;
          var _iteratorError = undefined;

          try {
            for (
              var _iterator = targetEle[Symbol.iterator](), _step;
              !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
              _iteratorNormalCompletion = true
            ) {
              var ele = _step.value;

              $(ele).val(newValue);
            }
          } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
          } finally {
            try {
              if (!_iteratorNormalCompletion && _iterator.return) {
                _iterator.return();
              }
            } finally {
              if (_didIteratorError) {
                throw _iteratorError;
              }
            }
          }

          console.log("ID: " + id + " has been changed to " + newValue);
        }
      });
    });
    // end ↑ ajax
  });

  // 添加关联
  $("#add_simple_frame").on("click", function() {
    var liTemp = document
      .getElementById("chanpin_simple_content")
      .cloneNode(true);
    window.inori = liTemp;
    liTemp.id = "";
    liTemp.getElementsByTagName("input")[1].value = "";
    liTemp.getElementsByTagName("input")[0].value = "";
    $(".chanpin_simple").append(liTemp);
  });
  // 标签删除
  $(".tag_row").on({ contextmenu: rightClickMenu }, {});
  // 给input标签添加title，如果有title就不添加
  $.each($("input, textarea"), function(index, item) {
    var target = $(item);
    if (!!!target.attr("title"))
      target.attr("title", target.attr("placeholder"));
  });
});

// 利息计算
function lixi_calc() {
  $(".lixi_fenbu_main").each(function(index, item) {
    $(item)
      .find(".huankuan_fangshi")
      .on({ change: recalLX }, {});
    $(item)
      .find(".min_lixi")
      .on({ change: recalLX }, {});
    $(item)
      .find(".max_time")
      .on({ change: recalLX }, {});
  });
}
// 利息计算事件函数
function recalLX(evt) {
  // （100000(10万)/最长期数）+（100000（10万）X 最低利息X0.01）
  // 利息是 先息后本 则计算公式为（100000（10万）X 最低利息X0.01
  var parentEle = $(evt.target).closest(".lixi_fenbu_main");
  var minLixi = Number(
    parentEle
      .find(".min_lixi")
      .val()
      .replace(/[^\d.]/g, "")
  );
  var payType = String(parentEle.find(".huankuan_fangshi").val());
  var maxTime =
    Number(
      parentEle
        .find(".max_time")
        .val()
        .replace(/\D/g, "")
    ) > 360 ||
    Number(
      parentEle
        .find(".max_time")
        .val()
        .replace(/\D/g, "")
    ) === 0
      ? 36
      : Number(
          parentEle
            .find(".max_time")
            .val()
            .replace(/\D/g, "")
        );
  var lixiRecal = parentEle.find(".lixi_recal");
  var lixiValue = 0;
  // 处理数字并回填
  parentEle.find(".min_lixi").val(minLixi);
  parentEle.find(".max_time").val(maxTime);
  if (payType === "先息后本") {
    lixiValue = 1e5 * minLixi * 0.01;
    parentEle.find(".shouldMind").css("display", "unset");
  } else if (payType === "等额本息" || payType === "等额本金" || payType === "等本等息") {
    lixiValue = 1e5 / maxTime + 1e5 * minLixi * 0.01;
    parentEle.find(".shouldMind").css("display", "none");
  }
  lixiRecal.text("0");
  if (lixiValue < 1e5 && lixiValue > 0)
    lixiRecal.text(lixiValue.toFixed(3) + " ");
  else lixiRecal.text("--- ");
}

// 右击删除标签
function rightClickMenu(evt) {
  // 限定在有right-click元素，防止错误响应
  if (
    !$(evt.target).attr("right-click") ||
    ($(evt.target).attr("right-click") !== "true" &&
      $(evt.target).attr("right-click") !== "xiaolei")
  ) {
    return;
  }
  evt.preventDefault();
  // 弹窗确认
  var shouldDelete = confirm("确定删除这个标签？");
  if (shouldDelete) {
    // 如果标签已经被激活
    if (
      $(evt.target)
        .closest(".tag_content")
        .hasClass("active") ||
      ("" +
        $(evt.target)
          .closest('[class^="multi_row"]')
          .find("textarea")
          .val()).match($(evt.target).text())
    ) {
      alert("删除失败！标签正在被产品引用，请先保存相关产品后重试");
      console.log("本页产品就使用了这个标签！怎么删");
      return;
    }
    var ajaxUrl = "" + $("#ajax_del_biaoqian").val();
    var ajaxData = {
      biaoqian_id: ("" + $(evt.target).attr("id")).replace(/_/, ""), // 标签id
      biaoqian_type:
        "" +
        $(evt.target)
          .closest(".tag_row")
          .attr("tag-type") // 标签类型
    };
    if ($(evt.target).attr("right-click") === "xiaolei") {
      var tagID = $(evt.target).attr("inori-data");
      ajaxData.biaoqian_id = "" + $("#hidden_tag #" + tagID).attr("value");
    }
    if (
      !ajaxUrl ||
      !ajaxData.biaoqian_id ||
      !ajaxData.biaoqian_type ||
      ajaxData.biaoqian_id === "undefined" ||
      ajaxData.biaoqian_type === "undefined"
    ) {
      alert("删除标签需要的数据不完整！");
      console.log("删除标签需要的数据不完整:");
      console.dir([ajaxUrl, ajaxData.biaoqian_id, ajaxData.biaoqian_type]);
      return;
    }
    $.ajax(ajaxUrl, {
      type: "post",
      data: ajaxData,
      beforeSend: function beforeSend() {
        alert("正在删除，请稍侯");
      }
    })
      .fail(function(err) {
        console.log(err);
        alert("删除失败");
      })
      .done(function(res) {
        if (!res.code || "" + res.code !== "2") {
          // 不正常
          if (!res.code) {
            alert("服务器返回未知内容！查看控制台获取更多信息");
            console.log(
              "\u5220\u9664\u6807\u7B7E\u65F6\uFF0C\u670D\u52A1\u5668\u8FD4\u56DE"
            );
            console.log(res);
          } else if ("" + res.code === "1") {
            if (res.data && res.data.length > 0) {
              alert(
                "\u5220\u9664\u5931\u8D25\uFF01\u6807\u7B7E\u6B63\u5728\u88AB\u4EA7\u54C1\u5F15\u7528( " +
                  res.data[0].litter_name +
                  " \u7B49)\uFF0C\u8BF7\u5148\u4FDD\u5B58\u76F8\u5173\u4EA7\u54C1\u540E\u91CD\u8BD5"
              );
            } else {
              alert("删除失败！标签正在被产品引用，请先保存相关产品后重试");
            }
            console.log(
              "\u5220\u9664\u6807\u7B7E\u65F6\uFF0C\u670D\u52A1\u5668\u8FD4\u56DE"
            );
            console.log(res);
          } else if ("" + res.code === "3") {
            alert("删除失败！请重试");
            console.log(
              "\u5220\u9664\u6807\u7B7E\u65F6\uFF0C\u670D\u52A1\u5668\u8FD4\u56DE"
            );
            console.log(res);
          } else if ("" + res.code === "4") {
            alert("删除失败！标签数据异常");
            console.log(
              "\u5220\u9664\u6807\u7B7E\u65F6\uFF0C\u670D\u52A1\u5668\u8FD4\u56DE"
            );
            console.log(res);
          }
        } else if (res.code && "" + res.code === "2") {
          // 正常
          layer.msg("删除成功");
          // 移除小类标签本体
          if ($(evt.target).attr("right-click") === "xiaolei") {
            var _tagID = $(evt.target).attr("inori-data");
            $(evt.target)
              .closest("span.tag_content")
              .remove();
            $("#hidden_tag #" + _tagID).remove();
          } else {
            // 移除标签本体
            var _tagID2 = $(evt.target).attr("id");
            var tagContnt = $(evt.target).text();
            // value = '{$vo.id}' id="{$vo.name}"
            debugger;
            $(evt.target)
              .closest("span.tag_content")
              .remove();
            $("#" + tagContnt + "[value='" + _tagID2 + "']").remove();
          }
        }
      });
  } else {
    return;
  }
}
